<div class="bjui-pageContent">
    <form method="post" action="${ctxPath}/system/cms/site/save" id="j_client_form" data-toggle="validate" data-autorefresh="true" data-alertmsg="false">
        <input TYPE="hidden" name="siteId" value="${site.siteId!}">
        <input type="hidden" id="initProvince2" value="${site.provinceCode!}">
        <input type="hidden" id="initCity2" value="${site.cityCode!}">

        <input type="hidden" name="template" value="${site.template!}">
        <input type="hidden" name="mobileTpl" value="${site.mobileTpl!}">
        <input type="hidden" name="siteKey" value="${site.siteKey!}">
        <input type="hidden" name="status" value="${site.status!}">
        <input type="hidden" name="isMobile" value="${site.isMobile!}">
        <input type="hidden" id="v-siteType" value="${site.siteType!}">

        <table class="table table-condensed table-hover" width="100%">
            <tbody>
            <tr>
                <td>
                    <label for="siteName" class="control-label x85">站点名称：</label>
                    <input type="text" name="siteName" id="siteName" value="${site.siteName!,xss}" placeholder="站点名称" data-rule="required;" >
                </td>
            </tr>
            <!--<tr>
                <td>
                    <label for="siteKey" class="control-label x85">站点路径：</label>
                    <input type="text" name="siteKey" id="siteKey" value="${site.siteKey!,xss}" placeholder="站点路径" >
                </td>
            </tr>-->
            <tr>
                <td>
                    <label for="domain" class="control-label x85">站点域名：</label>
                    @if(isEmpty(site.domain)){
                    <input type="text" name="domain" id="domain" value="${site.domain!,xss}" data-rule="required;remote(${ctxPath}/system/cms/site/checkDomain)"   placeholder="站点域名">
                    @}else{
                    <input type="text" name="domain" id="domain" value="${site.domain!,xss}" data-rule="required;"   placeholder="站点域名">
                    @}
                </td>
            </tr>
            <!--<tr>
                <td>
                    <label class="control-label x85">logo：</label>
                    <div style="display: inline-block; vertical-align: middle;">
                        <div id="j_site_logo_up" data-toggle="upload" data-uploader="${ctxPath}/upload"
                             data-file-size-limit="1024000000"
                             data-file-type-exts="*.jpg;*.png;*.gif;*.mpg"
                             data-multi="false"
                             data-on-upload-success="pic_upload_success"
                             data-icon="cloud-upload"></div>
                        <input type="hidden" name="logo" value="${site.logo!}" id="j_site_logo">
                        <span id="j_site_logo_span_pic">
                            @if(isNotEmpty(site.logo)){
                            <IMG WIDTH="200" HEIGHT="120" src="${site.logo!}">
                            @}
                        </span>
                    </div>
                    <br>

                </td>
            </tr>-->
            <tr>
                <td>
                    <label class="control-label x85">管理员：</label>
                    <input type="text" data-toggle="lookup" data-rule="required;" readonly  data-url="${ctxPath}/system/cms/site/userCheck?siteId=${site.siteId!}" name="userIds" data-maxable="false" data-resizable="false"  data-width="750" data-height="430" data-title="选择管理员" value="${site.userIds!}">
                </td>
            </tr>
            <!--<tr>
                <td>
                    <label for="sl-siteType" class="control-label x85"  data-toggle="selectpicker">站点类型：</label>
                    <select name="siteType" data-rule="required" id="sl-siteType">

                    </select>
                </td>
            </tr>-->
            <tr>
                <td>
                    <label for="j_province" class="control-label x85"  data-toggle="selectpicker">所属城市：</label>
                    <select name="provinceCode" id="j_province" data-rule="required" data-width="100">
                        <option value="0">省份列表</option>
                    </select>
                    <select name="cityCode" id="j_city" data-width="100">
                     <!--<select name="cityCode" id="j_city" data-width="100" data-rule="remote(${ctxPath}/system/cms/site/checkCity, siteId)">-->
                        <!-- remote(${ctxPath}/system/cms/site/checkCity) -->
                        <option value="0">城市列表</option>
                    </select>
                </td>
            </tr>
            <!--<tr>
                <td>
                    <label for="j_status" class="control-label x85"  data-toggle="selectpicker">站点状态：</label>
                    <select name="status" id="j_status"  data-rule="required">
                        @if(isNotEmpty(site.status)&&!site.status){
                        <option value="1">正常</option>
                        <option value="0" selected>禁用</option>
                        @}else{
                        <option value="1" selected>正常</option>
                        <option value="0">禁用</option>
                        @}
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="j_mstatus" class="control-label x85"  data-toggle="selectpicker">开启移动：</label>
                    <select name="isMobile" id="j_mstatus"  data-rule="required">
                        @if(isNotEmpty(site.isMobile)&&!site.isMobile){
                        <option value="1">启用</option>
                        <option value="0" selected>禁用</option>
                        @}else{
                        <option value="1" selected>启用</option>
                        <option value="0">禁用</option>
                        @}
                    </select>
                </td>
            </tr>-->
            <tr>
                <td>
                    <label for="j_linkman" class="control-label x85">站点标题：</label>
                    <input type="text" name="title" id="j_linkman" value="${site.title!,xss}" placeholder="站点标题" data-rule="required" >
					<span style="color: red">（限100个汉字）</span>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="j_email" class="control-label x85">关键字：</label>
                    <input type="text" name="keyword" id="j_email" value="${site.keyword!,xss}" placeholder="关键字"  data-rule="required;">
					<span style="color: red">（限100个汉字）</span>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="j_mobile" class="control-label x85">描述：</label>
                    <input type="text" name="description" id="j_mobile" value="${site.description!,xss}"  placeholder="描述"  data-rule="required">
					<span style="color: red">（限200个汉字）</span>
                </td>
            </tr>

            <!--<tr>
                <td>
                    <label for="j_tpl" class="control-label x85">模板：</label>
                    <input type="text" name="template" id="j_tpl" value="${site.template!,xss}"  placeholder="模板"  data-rule="required">
                </td>
            </tr>
            <tr>
                <td>
                    <label for="j_tpl" class="control-label x85">手机模板：</label>
                    <input type="text" name="mobileTpl" id="j_mtpl" value="${site.mobileTpl!,xss}"  placeholder="模板"  data-rule="required">
                </td>
            </tr>-->
            <tr>
                <td>
                    <label for="sortId" class="control-label x85">站点排序：</label>
                    <input type="text" name="sortId" id="sortId" value="${site.sortId!,xss}" data-rule="required;integer[+]"   placeholder="排序，请输入正整数">
                </td>
            </tr>
            </tbody>
        </table>
    </form>
    </div>
<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-close" data-icon="close">关闭</button></li>
        <li><button type="submit" class="btn-default"  data-icon="save">保存</button></li>
    </ul>
</div>

<script type="text/javascript">
    (function () {
        var initProvince2 = $("#initProvince2").val();
        var initCity2 = $("#initCity2").val();
        if(initCity2 == null || initCity2 == "" || initCity2 == undefined){
            initCity2 = null;
        }

        getProviceList(false, "#j_province", "#j_city", initProvince2, initCity2);
        $("#j_province").change(function () {
            var provinceCode = this.value;
            getCityListByProvice(provinceCode, false, "#j_city", null);
        });


        /**
         * 获取省份列表
         * hasAll 是否含有全部
         * provinceElem 省份元素
         * cityElem 城市元素
         * initProvince 省份初始值
         * initCity 城市初始值
         */
        function getProviceList(hasAll, provinceElem, cityElem, initProvince, initCity){
            var url =  "${ctxPath}/city/getProviceList";
            $.post(url,null,function(data){
                var html = "";
                if(hasAll){
                    html += "<option value='0'>所有省份</option>";
                }
                var list = data.result;
                for(var i=0; i < list.length; i++){
                    if(initProvince != null && list[i].cityCode == initProvince){
                        html += "<option value='"+list[i].cityCode+"' selected>"+list[i].cityName+"</option>";
                        getCityListByProvice(list[i].cityCode, hasAll, cityElem, initCity);
                    }else{
                        html += "<option value='"+list[i].cityCode+"'>"+list[i].cityName+"</option>";
                    }
                    if(!hasAll && initCity == null && i == 0){
                        getCityListByProvice(list[i].cityCode, hasAll, cityElem, initCity);
                    }
                }
                $(provinceElem).html(html);
                $(provinceElem).selectpicker("refresh");
            },"json");
        };

        /**
         * 获取城市列表
         * hasAll 是否含有全部
         * provinceCode 省份code
         * cityElem 城市元素
         * initCity 城市初始值
         */
        function getCityListByProvice(provinceCode, hasAll, cityElem, initCity){
            var url = "${ctxPath}/city/getCityListByProvice";
            $.post(url,{provinceCode:provinceCode},function(data){
                var html = "";
                if(hasAll){
                    html += "<option value='0'>所有城市</option>";
                }
                var list = data.result;
                for(var i=0; i < list.length; i++){
                    if(initCity != null && list[i].cityCode == initCity){
                        html += "<option value='"+list[i].cityCode+"' selected>"+list[i].cityName+"</option>";
                    }else{
                        html += "<option value='"+list[i].cityCode+"'>"+list[i].cityName+"</option>";
                    }
                }
                $(cityElem).html(html);
                $(cityElem).selectpicker("refresh");
            },"json");
        };

        var siteType = $("#v-siteType").val();
        getSiteTypeList();

        /**
         * 根据父id查询站点类型列表
         */
        function getSiteTypeList() {
            var url =  "${ctxPath}/siteCode/listByPid";
            console.info(siteType);
            $.post(url,{pid:2},function(data){
                if(data.code == 0){
                    var html = "";
                    var list = data.result;
                    for(var i=0; i < list.length; i++){
                        if(siteType != null && list[i].code == siteType){
                            html += "<option value='"+list[i].code+"' selected>"+list[i].description+"</option>";
                        }else{
                            html += "<option value='"+list[i].code+"'>"+list[i].description+"</option>";
                        }
                    }
                    $("#sl-siteType").html(html);
                    $("#sl-siteType").selectpicker("refresh");
                }
            },"json");
        }

        function pic_upload_success(file, data) {
            var json = $.parseJSON(data);
            $(this).bjuiajax('ajaxDone', json);
            if (json[BJUI.keys.statusCode] == BJUI.statusCode.ok) {
                $('#j_site_logo').val(json.filename).trigger('validate');
                $('#j_site_logo_span_pic').html('<img src="'+ json.filename +'" WIDTH="200" HEIGHT="120"/>');
            }
        };
    })();
</script>
